package org.goobs.logic;

public class TruthValue {

	public static final int TRUE = 1;
	public static final int FALSE = 0;
	public static final int UNKNOWN = -1;
	
	private double truth;
	
	public TruthValue(double truth){
		this.truth = truth;
	}
	public TruthValue(boolean truth){
		if(truth){
			this.truth = 1.0;
		}else{
			this.truth = 0.0;
		}
	}
	public TruthValue(int truth){
		switch(truth){
		case TRUE:
			this.truth = 1.0;
			break;
		case FALSE:
			this.truth = 0.0;
			break;
		case UNKNOWN:
			this.truth = Double.NaN;
			break;
		default:
			throw new IllegalArgumentException("Invalid truth value: " + truth);
		}
	}
	
	public boolean isTrue(){
		return this.truth == 1.0;
	}
	public boolean isFalse(){
		return this.truth == 0.0;
	}
	public boolean hasTruth(){
		return this.truth != Double.NaN;
	}
	public double truthVal(){
		return this.truth;
	}
	
	public int boolVal(){
		if(truth == 1.0){
			return TRUE;
		}else if(truth == 0.0){
			return FALSE;
		}else if(truth == Double.NaN){
			return UNKNOWN;
		}else{
			return UNKNOWN;
		}
	}
	
}
